<template>
  <!-- 新增与复制 -->
  <div>
    <div>
      <FilterTable
        ref="table"
        columnsRef="partPartInfoManagePartInfoPartModel"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'rows'"
        selectionType="single"
        :onColumnsChange="columns => (this.columns = columns)"
        :onRowSelectChange="columns => (this.selectColumn = columns)"
      ></FilterTable>
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="saveDialog">确认</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryModel } from '@/api/part/partInfoManage/partInfo';

export default {
  name: 'Brand',
  components: {},
  mixins: [dictionary],
  data() {
    return {
      selectColumn: [],
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: queryModel,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {}
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '品牌',
          dataIndex: 'BRAND_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系代码',
          dataIndex: 'SERIES_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型代码',
          dataIndex: 'MODEL_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'MODEL_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    async saveDialog() {
      let modelName = this.selectColumn[0].MODEL_NAME;
      let modelCode = this.selectColumn[0].MODEL_CODE;
      let modelObj = { name: modelName, code: modelCode };
      this.$emit('close', modelObj);
    },
    closeDialog() {
      this.$emit('close');
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}仓库`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>
<style scoped></style>
